package cn.cas.mango.controller;

import cn.cas.mango.dto.param.AggParam;
import cn.cas.mango.dto.param.GlobalParam;
import cn.cas.mango.dto.param.News;
import cn.cas.mango.service.Agg;
import cn.cas.mango.service.GetClusterInfo;
import cn.cas.mango.service.PrintJson;
import cn.cas.mango.service.PrintJsonCluster;
import cn.cas.mango.service.TransNews;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/")
@ResponseBody
@CrossOrigin
public class Temp {
  @Autowired
  private PrintJson printJson;

  @Autowired
  private GetClusterInfo getClusterInfo;
  @Autowired
  private PrintJsonCluster printJsonCluster;
  @Autowired
  private TransNews transNews;
  @Autowired
  private Agg agg;

  @RequestMapping(value = "/es", method = {RequestMethod.GET, RequestMethod.POST})
  void tran2es(GlobalParam globalParam) throws IOException {
    printJson.main(globalParam);
  }

  @RequestMapping(value = "/agg", method = {RequestMethod.GET, RequestMethod.POST})
  JSONObject agg(AggParam aggParam)  {
    return agg.agg2(aggParam);
  }

  @RequestMapping(value = "/get", method = {RequestMethod.GET, RequestMethod.POST})
  JSONArray getOne(AggParam aggParam) {
    return agg.showOne(aggParam);
  }

  @RequestMapping(value = "/getd3", method = {RequestMethod.GET, RequestMethod.POST})
  JSONObject getD3(AggParam aggParam) {
    return agg.getD3(aggParam);
  }

  @RequestMapping(value = "/2cluster", method = {RequestMethod.GET, RequestMethod.POST})
  JSONObject secondCluster(AggParam aggParam) {
    return agg.temp(aggParam);
  }

  @RequestMapping(value = "/cluster", method = {RequestMethod.GET, RequestMethod.POST})
  JSONObject cluster(GlobalParam globalParam) {
    return printJsonCluster.main(globalParam);
  }

  @RequestMapping(value = "/getd3cluster", method = {RequestMethod.GET, RequestMethod.POST})
  JSONObject getD3Cluster(AggParam aggParam) {
    return getClusterInfo.getD3Cluster(aggParam);
  }

  @RequestMapping(value = "/getd3cluster2", method = {RequestMethod.GET, RequestMethod.POST})
  JSONObject getD3Cluster2(AggParam aggParam) {
    return getClusterInfo.getD3Cluster2(aggParam);
  }

  @RequestMapping(value = "/getinfo", method = {RequestMethod.GET, RequestMethod.POST})
  JSONArray getInfo() {
    return getClusterInfo.getInfo();
  }

  @RequestMapping(value = "/getJson", method = {RequestMethod.GET, RequestMethod.POST})
  JSONObject getJson() {
    return getClusterInfo.getJson();
  }

  @RequestMapping(value = "/getcsv", method = {RequestMethod.GET, RequestMethod.POST})
  void getCsv(AggParam aggParam) {
     getClusterInfo.getCsv(aggParam);
  }

  @RequestMapping(value = "/getcsv2", method = {RequestMethod.GET, RequestMethod.POST})
  void getCsv2(AggParam aggParam) {
    getClusterInfo.getCsv2(aggParam);
  }

  @RequestMapping(value = "/getall", method = {RequestMethod.GET, RequestMethod.POST})
  JSONArray getAll(AggParam aggParam) {
    return getClusterInfo.getAll(aggParam);
  }

  @RequestMapping(value = "/transnews", method = {RequestMethod.GET, RequestMethod.POST})
  JSONObject transNews(GlobalParam globalParam) {
    return transNews.transNews(globalParam);
  }
}
